<template>
	<view class="content">
		<image class="logo" src="/static/logo.png"></image>
		<view class="uni-flex uni-column">
			<text>姓名:</text>
			<input type="text" v-model="name" placeholder="输入名字" />
			<button @click="upStudent">上传</button>
			<view class="uni-flex uni-column">
				<view v-for="(i, index) in list" :key="index">
					<text>名字：{{ i.name }}</text>
					<button type="default" @click="delectOne(i._id)">删除</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			title: 'Hello',
			list: [],
			name: ''
		};
	},
	onLoad() {
		this.upfindallData();
		console.log(main);
	},
	methods: {
		delectOne(id) {
			console.log(uniCloud);
			uniCloud.callFunction({
				name: 'testuser',
				data: { type: 'delete', data: { _id: id } },
				success: res => {
					console.log(res);
					this.upfindallData();
				}
			});
		},
		upfindallData() {
			uniCloud.callFunction({
				name: 'testuser',
				data: { type: 'find' },
				success: res => {
					console.log(res.result);
					this.list = res.result.data;
				}
			});
		},
		upStudent() {
			if (this.name == '') {
				return;
			}
			uniCloud.callFunction({
				name: 'testuser',
				data: {
					type: 'add',
					data: {
						name: this.name
					}
				},
				success: res => {
					console.log(res);
					this.upfindallData();
				}
			});
		}
	}
};
</script>

<style>
.content {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
}

.logo {
	height: 200rpx;
	width: 200rpx;
	margin-top: 200rpx;
	margin-left: auto;
	margin-right: auto;
	margin-bottom: 50rpx;
}

.text-area {
	display: flex;
	justify-content: center;
}

.title {
	font-size: 36rpx;
	color: #8f8f94;
}
</style>
